<!DOCTYPE html><html lang="zh-CN" data-theme="dark"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"><title>面试题--MySQL | SodaSoda</title><meta name="author" content="ShiMH"><meta name="copyright" content="ShiMH"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#0d0d0d"><meta name="description" content="1.创建数据库1create database  if not exists 数据库名 default charset uft8 collate utf8_general_cli;  如果不存在则创建，设定编码集为utf8 2.删除数据库1drop database 数据库名;  3.选择数据库1use 数据库名;  4.数据类型​	数值类型：integer smallint decimal nu">
<meta property="og:type" content="article">
<meta property="og:title" content="面试题--MySQL">
<meta property="og:url" content="https://soda124.gitee.io/articles/b7aade44.html">
<meta property="og:site_name" content="SodaSoda">
<meta property="og:description" content="1.创建数据库1create database  if not exists 数据库名 default charset uft8 collate utf8_general_cli;  如果不存在则创建，设定编码集为utf8 2.删除数据库1drop database 数据库名;  3.选择数据库1use 数据库名;  4.数据类型​	数值类型：integer smallint decimal nu">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://soda124.gitee.io/img/star.jpeg">
<meta property="article:published_time" content="2022-06-21T00:31:16.000Z">
<meta property="article:modified_time" content="2022-06-30T07:49:55.924Z">
<meta property="article:author" content="ShiMH">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://soda124.gitee.io/img/star.jpeg"><link rel="shortcut icon" href="/img/favicon.png"><link rel="canonical" href="https://soda124.gitee.io/articles/b7aade44"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="stylesheet" href="/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@6/css/all.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.css" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = { 
  root: '/',
  algolia: undefined,
  localSearch: undefined,
  translate: undefined,
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":false},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '',
  date_suffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: undefined,
  lightbox: 'fancybox',
  Snackbar: undefined,
  source: {
    justifiedGallery: {
      js: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery@2/dist/fjGallery.min.js',
      css: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery@2/dist/fjGallery.min.css'
    }
  },
  isPhotoFigcaption: false,
  islazyload: true,
  isAnchor: false
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: '面试题--MySQL',
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2022-06-30 15:49:55'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          if (t === 'dark') activateDarkMode()
          else if (t === 'light') activateLightMode()
        
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
    const detectApple = () => {
      if(/iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
        document.documentElement.classList.add('apple')
      }
    }
    detectApple()
    })(window)</script><link rel="stylesheet" href="/css/universe.css"><link rel="stylesheet" href="/css/custom.css"><!-- hexo injector head_end start --><link rel="stylesheet" href="https://unpkg.zhimg.com/hexo-butterfly-clock/lib/clock.min.css" /><!-- hexo injector head_end end --><meta name="generator" content="Hexo 6.2.0"></head><body><div id="loading-box"><div class="loading-left-bg"></div><div class="loading-right-bg"></div><div class="wizard-scene"><div class="wizard-objects"><div class="wizard-square"></div><div class="wizard-circle"></div><div class="wizard-triangle"></div></div><div class="wizard"><div class="wizard-body"></div><div class="wizard-right-arm"><div class="wizard-right-hand"></div></div><div class="wizard-left-arm"><div class="wizard-left-hand"></div></div><div class="wizard-head"><div class="wizard-beard"></div><div class="wizard-face"><div class="wizard-adds"></div></div><div class="wizard-hat"><div class="wizard-hat-of-the-hat"></div><div class="wizard-four-point-star --first"></div><div class="wizard-four-point-star --second"></div><div class="wizard-four-point-star --third"></div></div></div></div></div></div><div id="web_bg"></div><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src= "/img/cat-loading.gif" data-lazy-src="/img/profileIcon.jpg" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="sidebar-site-data site-data is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">9</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">0</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">5</div></a></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fa fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fa fa-archive"></i><span> 时间轴</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fa fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fa fa-link"></i><span> 友链</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fa fa-sitemap"></i><span> 菜单</span></a></div></div></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header" style="background-image: url('/img/star.jpeg')"><nav id="nav"><span id="blog_name"><a id="site-name" href="/">SodaSoda</a></span><div id="menus"><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fa fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fa fa-archive"></i><span> 时间轴</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fa fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fa fa-link"></i><span> 友链</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fa fa-sitemap"></i><span> 菜单</span></a></div></div><div id="toggle-menu"><a class="site-page"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">面试题--MySQL</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2022-06-21T00:31:16.000Z" title="发表于 2022-06-21 08:31:16">2022-06-21</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2022-06-30T07:49:55.924Z" title="更新于 2022-06-30 15:49:55">2022-06-30</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/categories/%E9%9D%A2%E8%AF%95/">面试</a></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-wordcount"><i class="far fa-file-word fa-fw post-meta-icon"></i><span class="post-meta-label">字数总计:</span><span class="word-count">771</span><span class="post-meta-separator">|</span><i class="far fa-clock fa-fw post-meta-icon"></i><span class="post-meta-label">阅读时长:</span><span>3分钟</span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><h3 id="1-创建数据库"><a href="#1-创建数据库" class="headerlink" title="1.创建数据库"></a>1.创建数据库</h3><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">create database  if not exists 数据库名 default charset uft8 collate utf8_general_cli;</span><br></pre></td></tr></table></figure>

<p>如果不存在则创建，设定编码集为utf8</p>
<h3 id="2-删除数据库"><a href="#2-删除数据库" class="headerlink" title="2.删除数据库"></a>2.删除数据库</h3><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">drop database 数据库名;</span><br></pre></td></tr></table></figure>

<h3 id="3-选择数据库"><a href="#3-选择数据库" class="headerlink" title="3.选择数据库"></a>3.选择数据库</h3><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">use 数据库名;</span><br></pre></td></tr></table></figure>

<h3 id="4-数据类型"><a href="#4-数据类型" class="headerlink" title="4.数据类型"></a>4.数据类型</h3><p>​	数值类型：integer smallint decimal numeric float  double </p>
<p>​	日期和时间：date time year datetime timestamp</p>
<p>​	字符串类型：char varchar binary varbinary blob text enum set</p>
<h3 id="5-创建数据表"><a href="#5-创建数据表" class="headerlink" title="5.创建数据表"></a>5.创建数据表</h3><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">create table if not exists `runoob_tbl`(</span><br><span class="line"></span><br><span class="line">`runoob_id` int unsigned auto_increment,</span><br><span class="line"></span><br><span class="line">`runoob_title` varchar(100) not null,</span><br><span class="line"></span><br><span class="line">`runoob_author` varchar(40) not null,</span><br><span class="line"></span><br><span class="line">`submission_date` date,</span><br><span class="line"></span><br><span class="line">primary key (`runoob_id`)</span><br><span class="line"></span><br><span class="line">)engine=innodb default charset=utf8;</span><br></pre></td></tr></table></figure>

<h3 id="6-删除数据表"><a href="#6-删除数据表" class="headerlink" title="6.删除数据表"></a>6.删除数据表</h3><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">drop table 数据表名；</span><br></pre></td></tr></table></figure>

<h3 id="7-插入数据"><a href="#7-插入数据" class="headerlink" title="7.插入数据"></a>7.插入数据</h3><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">insert into table_name (field1, field2,...fieldn)</span><br><span class="line"></span><br><span class="line">values</span><br><span class="line"></span><br><span class="line">(value1,value2,...valuen),</span><br><span class="line"></span><br><span class="line">((value1,value2,...valuen)...;</span><br></pre></td></tr></table></figure>

<h3 id="8-查询数据"><a href="#8-查询数据" class="headerlink" title="8.查询数据"></a>8.查询数据</h3><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">select column_name,column_name from table_name</span><br><span class="line"></span><br><span class="line">where</span><br></pre></td></tr></table></figure>

<h3 id="9-修改数据"><a href="#9-修改数据" class="headerlink" title="9.修改数据"></a>9.修改数据</h3><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">update table_name set field1=new-value1, field2=new-value2</span><br><span class="line"></span><br><span class="line">where</span><br></pre></td></tr></table></figure>

<h3 id="10-批量替换"><a href="#10-批量替换" class="headerlink" title="10.批量替换"></a>10.批量替换</h3><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">update table_name set runoob_title=replace(runoob_title,&#x27;c++&#x27;,&#x27;pyhton&#x27;)</span><br><span class="line"></span><br><span class="line">where</span><br></pre></td></tr></table></figure>

<h3 id="11-删除数据"><a href="#11-删除数据" class="headerlink" title="11.删除数据"></a>11.删除数据</h3><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">delete from table_name</span><br><span class="line"></span><br><span class="line">where</span><br></pre></td></tr></table></figure>

<h3 id="12-模糊查找Like"><a href="#12-模糊查找Like" class="headerlink" title="12.模糊查找Like"></a>12.模糊查找Like</h3><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">select * from runoob_tbl where runoob_author like &#x27;%COM&#x27;;     </span><br></pre></td></tr></table></figure>

<p> (不加%则 like 和 &#x3D; 的作用相同)</p>
<p>%表示n个数据    _表示1个数据</p>
<p>[ ]表示括号内所列字符的任意一个 ， [^]表示不在括号所列之内的单个字符</p>
<h3 id="13-UNION"><a href="#13-UNION" class="headerlink" title="13.UNION"></a>13.UNION</h3><p>连接两个以上的select语句的结果，并组合到一个集合中，默认DISTINCT（可选all）</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">SELECT expression1, expression2, ... expression_n</span><br><span class="line"></span><br><span class="line">FROM tables</span><br><span class="line"></span><br><span class="line">[WHERE conditions]</span><br><span class="line"></span><br><span class="line">**UNION** [ALL | DISTINCT]</span><br><span class="line"></span><br><span class="line">SELECT expression1, expression2, ... expression_n</span><br><span class="line"></span><br><span class="line">FROM tables</span><br><span class="line"></span><br><span class="line">[WHERE conditions];</span><br></pre></td></tr></table></figure>

<h3 id="14-排序ORDER-BY"><a href="#14-排序ORDER-BY" class="headerlink" title="14.排序ORDER BY"></a>14.排序ORDER BY</h3><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">select * from runoob_tbl order by submission_date ASC;</span><br><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h3 id="15-group-by"><a href="#15-group-by" class="headerlink" title="15. group by"></a>15. group by</h3><p>根据一个或多个列对结果集进行分组，分组列上可以使用count，sum，avg等函数</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">select name,count(*) from emplyee_tbl group by name [with rollup];（rollup用于求和）</span><br><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h3 id="16-连接"><a href="#16-连接" class="headerlink" title="16.连接"></a>16.连接</h3><p>内连接：</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">SELECT a.runoob_id, a.runoob_author, b.runoob_count </span><br><span class="line"></span><br><span class="line">FROM runoob_tbl a **INNER JOIN** tcount_tbl b </span><br><span class="line"></span><br><span class="line">**ON** a.runoob_author = b.runoob_author;</span><br></pre></td></tr></table></figure>

<p>等价于</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">SELECT a.runoob_id, a.runoob_author, b.runoob_count</span><br><span class="line"></span><br><span class="line">FROM runoob_tbl a, tcount_tbl b</span><br><span class="line"></span><br><span class="line">WHERE a.runoob_author = b.runoob_author;</span><br></pre></td></tr></table></figure>

<p>左外连接：</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">SELECT a.runoob_id, a.runoob_author, b.runoob_count </span><br><span class="line"></span><br><span class="line">FROM runoob_tbl a **LEFT JOIN** tcount_tbl b **ON** a.runoob_author = b.runoob_author;</span><br></pre></td></tr></table></figure>

<h3 id="17-事务"><a href="#17-事务" class="headerlink" title="17.事务"></a>17.事务</h3><p>原子性、一致性、隔离性、持久性</p>
<p>undolog                锁和mvcc  redolog</p>
<p>begin开始一个事务</p>
<p>rollback事务回滚</p>
<p>commit事务确认</p>
<h3 id="18-数据表结构修改alter"><a href="#18-数据表结构修改alter" class="headerlink" title="18.数据表结构修改alter"></a>18.数据表结构修改alter</h3><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">alter table runoob_tbl drop runoob_author; #删除列</span><br><span class="line"></span><br><span class="line">alter table runoob_tbl add runoob_author; #添加列</span><br><span class="line"></span><br><span class="line">ALTER TABLE testalter_tbl RENAME TO alter_tbl; #重命名表</span><br></pre></td></tr></table></figure>

<h3 id="19-索引"><a href="#19-索引" class="headerlink" title="19.索引"></a>19.索引</h3><p>作用：提高查询效率（索引和实际存储的数据都是存在磁盘中，在数据读取时会优先把索引加载在内存中）</p>
<p>格式：key-value</p>
<p>数据结构：B+树（一般情况下3-4层的B+树足以支撑千万级别的数据存储）</p>
<blockquote>
<p>为什么？：索引的瓶颈在于IO问题，所以应减少IO量，减少IO次数</p>
</blockquote>
<p>1.B+树的磁盘IO代价更低：B+树更矮，意味着数据库索引中更少的磁盘I&#x2F;O操作，更快的速度；</p>
<p>2.B+树的查询效率更加稳定：所有关键字查询的路径长度相同，导致每一个数据的查询效率相当；</p>
<p>3.B+树更加适合在区间查询：由于B+树的数据都存储在叶子结点中，分支结点均为索引，方便扫库，只需要扫一遍叶子结点即可，	所以B+树更加适合在区间查询的情况；</p>
</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">文章作者: </span><span class="post-copyright-info"><a href="https://soda124.gitee.io">ShiMH</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">文章链接: </span><span class="post-copyright-info"><a href="https://soda124.gitee.io/articles/b7aade44.html">https://soda124.gitee.io/articles/b7aade44.html</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="https://soda124.gitee.io" target="_blank">SodaSoda</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"></div><div class="post_share"><div class="social-share" data-image="/img/star.jpeg" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/social-share.js/dist/css/share.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/gh/overtrue/share.js@master/dist/js/social-share.min.js" defer></script></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/articles/40393ae2.html"><img class="prev-cover" src= "/img/cat-loading.gif" data-lazy-src="/img/star.jpeg" onerror="onerror=null;src='/img/404.jpg'" alt="cover of previous post"><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info">面试题--Java算法</div></div></a></div><div class="next-post pull-right"><a href="/articles/9505f082.html"><img class="next-cover" src= "/img/cat-loading.gif" data-lazy-src="/img/star.jpeg" onerror="onerror=null;src='/img/404.jpg'" alt="cover of next post"><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">面试题--数据库</div></div></a></div></nav></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="is-center"><div class="avatar-img"><img src= "/img/cat-loading.gif" data-lazy-src="/img/profileIcon.jpg" onerror="this.onerror=null;this.src='/img/friend_404.gif'" alt="avatar"/></div><div class="author-info__name">ShiMH</div><div class="author-info__description">未完待续</div></div><div class="card-info-data site-data is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">9</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">0</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">5</div></a></div><a id="card-info-btn" target="_blank" rel="noopener" href="https://github.com/xxxxxx"><i class="fab fa-github"></i><span>Follow Me</span></a><div class="card-info-social-icons is-center"><a class="social-icon" href="mailto:xxxxxx@gmail.com" target="_blank" title="Email"><i class="fas fa-envelope"></i></a></div></div><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn fa-shake"></i><span>公告</span></div><div class="announcement_content">来日方长</div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span><span class="toc-percentage"></span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-3"><a class="toc-link" href="#1-%E5%88%9B%E5%BB%BA%E6%95%B0%E6%8D%AE%E5%BA%93"><span class="toc-number">1.</span> <span class="toc-text">1.创建数据库</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2-%E5%88%A0%E9%99%A4%E6%95%B0%E6%8D%AE%E5%BA%93"><span class="toc-number">2.</span> <span class="toc-text">2.删除数据库</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#3-%E9%80%89%E6%8B%A9%E6%95%B0%E6%8D%AE%E5%BA%93"><span class="toc-number">3.</span> <span class="toc-text">3.选择数据库</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#4-%E6%95%B0%E6%8D%AE%E7%B1%BB%E5%9E%8B"><span class="toc-number">4.</span> <span class="toc-text">4.数据类型</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#5-%E5%88%9B%E5%BB%BA%E6%95%B0%E6%8D%AE%E8%A1%A8"><span class="toc-number">5.</span> <span class="toc-text">5.创建数据表</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#6-%E5%88%A0%E9%99%A4%E6%95%B0%E6%8D%AE%E8%A1%A8"><span class="toc-number">6.</span> <span class="toc-text">6.删除数据表</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#7-%E6%8F%92%E5%85%A5%E6%95%B0%E6%8D%AE"><span class="toc-number">7.</span> <span class="toc-text">7.插入数据</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#8-%E6%9F%A5%E8%AF%A2%E6%95%B0%E6%8D%AE"><span class="toc-number">8.</span> <span class="toc-text">8.查询数据</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#9-%E4%BF%AE%E6%94%B9%E6%95%B0%E6%8D%AE"><span class="toc-number">9.</span> <span class="toc-text">9.修改数据</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#10-%E6%89%B9%E9%87%8F%E6%9B%BF%E6%8D%A2"><span class="toc-number">10.</span> <span class="toc-text">10.批量替换</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#11-%E5%88%A0%E9%99%A4%E6%95%B0%E6%8D%AE"><span class="toc-number">11.</span> <span class="toc-text">11.删除数据</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#12-%E6%A8%A1%E7%B3%8A%E6%9F%A5%E6%89%BELike"><span class="toc-number">12.</span> <span class="toc-text">12.模糊查找Like</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#13-UNION"><span class="toc-number">13.</span> <span class="toc-text">13.UNION</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#14-%E6%8E%92%E5%BA%8FORDER-BY"><span class="toc-number">14.</span> <span class="toc-text">14.排序ORDER BY</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#15-group-by"><span class="toc-number">15.</span> <span class="toc-text">15. group by</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#16-%E8%BF%9E%E6%8E%A5"><span class="toc-number">16.</span> <span class="toc-text">16.连接</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#17-%E4%BA%8B%E5%8A%A1"><span class="toc-number">17.</span> <span class="toc-text">17.事务</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#18-%E6%95%B0%E6%8D%AE%E8%A1%A8%E7%BB%93%E6%9E%84%E4%BF%AE%E6%94%B9alter"><span class="toc-number">18.</span> <span class="toc-text">18.数据表结构修改alter</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#19-%E7%B4%A2%E5%BC%95"><span class="toc-number">19.</span> <span class="toc-text">19.索引</span></a></li></ol></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/articles/b8631032.html" title="信息加解密">信息加解密</a><time datetime="2022-08-26T00:00:00.000Z" title="发表于 2022-08-26 08:00:00">2022-08-26</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/articles/f119c603.html" title="AOP面向切面编程">AOP面向切面编程</a><time datetime="2022-08-25T09:06:00.000Z" title="发表于 2022-08-25 17:06:00">2022-08-25</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/articles/e1945976.html" title="Vue--父子传值">Vue--父子传值</a><time datetime="2022-07-28T04:30:00.000Z" title="发表于 2022-07-28 12:30:00">2022-07-28</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/articles/40393ae2.html" title="面试题--Java算法">面试题--Java算法</a><time datetime="2022-07-28T04:00:00.000Z" title="发表于 2022-07-28 12:00:00">2022-07-28</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/articles/b7aade44.html" title="面试题--MySQL">面试题--MySQL</a><time datetime="2022-06-21T00:31:16.000Z" title="发表于 2022-06-21 08:31:16">2022-06-21</time></div></div></div></div></div></div></main><footer id="footer" style="background-image: url('/img/star.jpeg')"><div id="footer-wrap"><div class="copyright">&copy;2022  <i id="heartbeat" class="fa fas fa-heartbeat"></i> ShiMH</div><div class="framework-info"><span>框架 </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>主题 </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div></div><link rel="stylesheet" href="https://fastly.jsdelivr.net/gh/HCLonely/images@master/others/heartbeat.min.css"></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><button id="go-up" type="button" title="回到顶部"><i class="fas fa-arrow-up"></i></button></div></div><div><script src="/js/utils.js"></script><script src="/js/main.js"></script><script src="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.umd.js"></script><script src="https://cdn.jsdelivr.net/npm/vanilla-lazyload/dist/lazyload.iife.min.js"></script><script async="async">var preloader = {
  endLoading: () => {
    document.body.style.overflow = 'auto';
    document.getElementById('loading-box').style.transition = 'opacity 3s ease 0s'
    document.getElementById('loading-box').style.opacity = '0'
    setTimeout(function(){
      document.getElementById('loading-box').classList.add("loaded")
    }, 3000);
  },
  initLoading: () => {
    document.body.style.overflow = '';
    document.getElementById('loading-box').style.transition = '';
    document.getElementById('loading-box').style.opacity = '1'
    document.getElementById('loading-box').classList.remove("loaded")

  }
}
window.addEventListener('load',()=> {preloader.endLoading()})
setTimeout(function(){preloader.endLoading();}, 3000);</script><div class="js-pjax"></div><canvas id="universe"></canvas><script defer src="/js/universe.js"></script><script defer src="/js/heart.js"></script><script id="click-heart" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/dist/click-heart.min.js" async="async" mobile="false"></script><script src="https://cdn.jsdelivr.net/npm/pjax/pjax.min.js"></script><script>let pjaxSelectors = ["head > title","#config-diff","#body-wrap","#rightside-config-hide","#rightside-config-show",".js-pjax"]

var pjax = new Pjax({
  elements: 'a:not([target="_blank"])',
  selectors: pjaxSelectors,
  cacheBust: false,
  analytics: false,
  scrollRestoration: false
})

document.addEventListener('pjax:send', function () {

  // removeEventListener scroll 
  window.tocScrollFn && window.removeEventListener('scroll', window.tocScrollFn)
  window.scrollCollect && window.removeEventListener('scroll', scrollCollect)

  typeof preloader === 'object' && preloader.initLoading()
  document.getElementById('rightside').style.cssText = "opacity: ''; transform: ''"
  
  if (window.aplayers) {
    for (let i = 0; i < window.aplayers.length; i++) {
      if (!window.aplayers[i].options.fixed) {
        window.aplayers[i].destroy()
      }
    }
  }

  typeof typed === 'object' && typed.destroy()

  //reset readmode
  const $bodyClassList = document.body.classList
  $bodyClassList.contains('read-mode') && $bodyClassList.remove('read-mode')

})

document.addEventListener('pjax:complete', function () {
  window.refreshFn()

  document.querySelectorAll('script[data-pjax]').forEach(item => {
    const newScript = document.createElement('script')
    const content = item.text || item.textContent || item.innerHTML || ""
    Array.from(item.attributes).forEach(attr => newScript.setAttribute(attr.name, attr.value))
    newScript.appendChild(document.createTextNode(content))
    item.parentNode.replaceChild(newScript, item)
  })

  GLOBAL_CONFIG.islazyload && window.lazyLoadInstance.update()

  typeof chatBtnFn === 'function' && chatBtnFn()
  typeof panguInit === 'function' && panguInit()

  // google analytics
  typeof gtag === 'function' && gtag('config', '', {'page_path': window.location.pathname});

  // baidu analytics
  typeof _hmt === 'object' && _hmt.push(['_trackPageview',window.location.pathname]);

  typeof loadMeting === 'function' && document.getElementsByClassName('aplayer').length && loadMeting()

  // prismjs
  typeof Prism === 'object' && Prism.highlightAll()

  typeof preloader === 'object' && preloader.endLoading()
})

document.addEventListener('pjax:error', (e) => {
  if (e.request.status === 404) {
    pjax.loadUrl('/404.html')
  }
})</script></div><!-- hexo injector body_end start --><script data-pjax>
  function butterfly_clock_injector_config(){
    var parent_div_git = document.getElementsByClassName('sticky_layout')[0];
    var item_html = '<div class="card-widget card-clock"><div class="card-glass"><div class="card-background"><div class="card-content"><div id="hexo_electric_clock"><img class="entered loading" id="card-clock-loading" src= "/img/cat-loading.gif" data-lazy-src="https://github.com/Monic1e/picb/tree/master/loading.gif" style="height: 120px; width: 100%;" data-ll-status="loading"/></div></div></div></div></div>';
    console.log('已挂载butterfly_clock')
    parent_div_git.insertAdjacentHTML("afterbegin",item_html)
    }
  var elist = 'null'.split(',');
  var cpage = location.pathname;
  var epage = 'all';
  var flag = 0;

  for (var i=0;i<elist.length;i++){
    if (cpage.includes(elist[i])){
      flag++;
    }
  }

  if ((epage ==='all')&&(flag == 0)){
    butterfly_clock_injector_config();
  }
  else if (epage === cpage){
    butterfly_clock_injector_config();
  }
  </script><script src="https://pv.sohu.com/cityjson?ie=utf-8"></script><script data-pjax src="https://unpkg.zhimg.com/hexo-butterfly-clock/lib/clock.min.js"></script><!-- hexo injector body_end end --></body></html>